package repository.beans;

import java.util.List;

import javax.ejb.Stateless;

import model.Candidate;
import model.Comment;
import model.Position;
import repository.CandidateRepository;
import repository.exceptions.RepositoryException;

@Stateless(name = "CandidateRepository", mappedName = "ejb/CandidateRepository")
public class CandidateRepositoryBean extends BaseRepositoryBean<Candidate, Long> implements CandidateRepository{

	public CandidateRepositoryBean() {
		super(Candidate.class);
	}

	@Override
	public List<Comment> getCommentsForCandidate(Long id)
			throws RepositoryException {
		Candidate c=this.getById(id);
		return c.getComments();
	}

	@Override
	public void addCommentToCandidate(Long id, Comment com) throws RepositoryException{
			
		Candidate c=this.getById(id);
		List<Comment> comms=c.getComments();
		comms.add(com);
		c.setComments(comms);
		this.merge(c);
		
	}

	@Override
	public Candidate getCandidateByName(String string)
			throws RepositoryException {
		for(Candidate c:this.getAll()){
			if(c.getFirstName().equals(string)){
				return c;
			}
		}
		return null;
	}

}
